Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Flexible Sync #5301

Merged
merged 39 commits into from
Jan 27, 2023
Merged

Support Flexible Sync #5301

merged 39 commits into from
Jan 27, 2023

Conversation

elle-j
Copy link
Contributor

@elle-j elle-j commented Jan 23, 2023

What, How & Why?

Adds support for Flexible Sync and Asymmetric Sync.

Flexible Sync:

  • Open a Flexible Sync realm by providing a realm configuration containing flexible: true and optionally an initialSubscriptions object:
const realmConfig: Configuration = {
  sync: {
    user,
    flexible: true,
    initialSubscriptions: {
      update: (mutableSubscriptions, realm) => {
        // ...
      } 
    },
  },

  // Other fields..
};
  • Get a realm's subscription set: realm.subscriptions
  • Manipulate the subscription set:
await realm.subscriptions.update(mutableSubs => {
  mutableSubs.add(realm.objects("Cat").filtered("age > 10"));
  mutableSubs.add(realm.objects("Dog").filtered("age > 20"), { name: "oldDogs" });
  mutableSubs.removeByName("youngDogs");
});

Asymmetric Sync:

  • User can set asymmetric: true in schema of a Realm object. If set, then:
    • Realm.create() will return undefined rather than the object itself.
    • Querying asymmetric object(s) will throw an error.

Review Notes:

  • packages/realm/src/schema/validate.ts does not need to be reviewed. The content here has merely been moved from Configuration.ts.

API change:

  • Internal:
    • Opening a synced realm locally:
      • Previous realm config type: { sync?: SyncConfiguration | true } where sync must be true.
      • New realm config type: { sync?: SyncConfiguration; openSyncedRealmLocally?: true }

Will be added in a separate PR:

  • Implementation of JS array methods on BaseSubscriptionSet such as join, filter, every, concat, etc. so that it can extend ReadonlyArray<Subscription>.

This closes #4806 and #5270.

☑️ ToDos

  • 🚦 Tests
  • 🔀 Executed flexible sync tests locally if modifying flexible sync

@cla-bot cla-bot bot added the cla: yes label Jan 23, 2023
packages/realm/src/Realm.ts Outdated Show resolved Hide resolved
Comment on lines +1 to +2
////////////////////////////////////////////////////////////////////////////
//
Copy link
Contributor Author

@elle-j elle-j Jan 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file does not need to be reviewed. The content is merely moved from Configuration.ts into this /schema/validate.ts file.

@elle-j elle-j mentioned this pull request Jan 23, 2023
1 task
packages/bindgen/src/realm_js_helpers.h Outdated Show resolved Hide resolved
packages/realm/src/Configuration.ts Show resolved Hide resolved
packages/realm/src/Realm.ts Outdated Show resolved Hide resolved
packages/realm/src/Realm.ts Outdated Show resolved Hide resolved
packages/realm/src/app-services/SubscriptionSet.ts Outdated Show resolved Hide resolved
packages/realm/src/app-services/BaseSubscriptionSet.ts Outdated Show resolved Hide resolved
RealmEventName,
RealmListenerCallback,
SubscriptionOptions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kraenhansen Do you know why?

Copy link
Contributor

@takameyer takameyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I have a few general questions just to broaden my understanding of things (could be answered by other reviewers). Other than that, I would like my this.timeout issue to be addressed and this is good to go in my eyes 👍🏼

integration-tests/tests/src/tests/sync/flexible.ts Outdated Show resolved Hide resolved
integration-tests/tests/src/tests/sync/sync-as-local.ts Outdated Show resolved Hide resolved
const { path, schema, onMigration, sync } = config;
if (typeof onMigration !== "undefined") {
assert.function(onMigration, "migration");
assert.object(config, "realm configuration", { allowArrays: false });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make sense. What's holding that back?

@@ -593,11 +630,11 @@ export class Realm {
this.syncSession?.resetInternal();
}

// TODO: Support embedded objects and asymmetric sync
// TODO: Support embedded objects
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a general question, but do we have a task to track this? I haven't heard embedded object support mentioned in any of our planning meetings

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we already supported them. If not, I would expect (hope!) that we would have some failing tests related to that.

packages/realm/src/Realm.ts Show resolved Hide resolved
packages/realm/src/Realm.ts Outdated Show resolved Hide resolved
@@ -75,6 +75,10 @@ export class Results<T = unknown> extends OrderedCollection<T> {
return this.internal.size();
}

description(): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question: is the description the filtered string?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is core's representation of the query. Some SDKs are not using RQL so it is a serialization of the query.

Copy link
Contributor

@kneth kneth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the comments have been resolved, it is ready to be merged.

It is a very big PR, and it has many moving parts. I am happy to see that you have been able to pull it through.

@@ -45,24 +45,41 @@ describe.skipIf(environment.missingServer, "Asymmetric sync", function () {
},
});

it("Schema with asymmetric = true and embedded = false", function () {
it("Schema with asymmetric = true and embedded = false", function (this: RealmContext) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(General comment, not specific to this line)

Should any of these changes be backported to the master branch or are they bindgen-specific? Ideally, we want the tests in bindgen and master to be as in-sync as possible since that is how we are ensuring that we don't change behavior (except where we intend to!)

packages/bindgen/spec.yml Outdated Show resolved Hide resolved
packages/bindgen/src/realm_js_helpers.h Show resolved Hide resolved
packages/bindgen/src/realm_js_helpers.h Outdated Show resolved Hide resolved
packages/realm/src/app-services/SyncConfiguration.ts Outdated Show resolved Hide resolved
/**
* Validate the fields of a user-provided realm sync configuration.
*/
export function validateSyncConfiguration(config: unknown): asserts config is SyncConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@internal?

Also I'm not sure if it is a good idea to split parsing and validation like this. It seems easy for them to get out of sync. Not sure if you want to change this now, but something to consider adding to a todo list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make a note of this 👍 Also good to be discussed in the team.

packages/realm/src/app-services/SyncConfiguration.ts Outdated Show resolved Hide resolved
packages/realm/src/app-services/SyncConfiguration.ts Outdated Show resolved Hide resolved
packages/realm/src/app-services/SyncConfiguration.ts Outdated Show resolved Hide resolved
@elle-j elle-j merged commit 75c35d8 into bindgen Jan 27, 2023
@elle-j elle-j deleted the lj/bindgen/flexible-sync branch January 27, 2023 15:51
kraenhansen added a commit that referenced this pull request Mar 1, 2023
kraenhansen added a commit that referenced this pull request Mar 3, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants